package com.jy.adscm.zltx.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.zltx.bean.SjFile;
import com.jy.adscm.zltx.bean.SjIssueRecycling;
import com.jy.adscm.zltx.mapper.mysql.SjFileMapper;
import com.jy.adscm.zltx.mapper.mysql.SjIssueRecyclingMapper;
import com.jy.adscm.zltx.service.SjIssueRecyclingService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2018-11-08
 */
@Service
public class SjIssueRecyclingServiceImpl extends ServiceImpl<SjIssueRecyclingMapper, SjIssueRecycling> implements SjIssueRecyclingService {
    @Autowired
    SjFileMapper SjFileMapper;
    @Autowired
    JyUserMapper jyUserMapper;
    @Override
    public boolean insertSjIssueRecycling(SjIssueRecycling sjIssueRecycling) {
        SjFile sjFile = SjFileMapper.selectById(sjIssueRecycling.getFileId());
        if (sjFile!=null){
            sjIssueRecycling.setVersionCode(sjFile.getVersionCode());
        }
        boolean insert = super.insert(sjIssueRecycling);
        return insert;
    }

    @Override
    public List<SjIssueRecycling> selectByFileId( Integer fileId) {
        Wrapper<SjIssueRecycling> wrapper =new EntityWrapper<>();
        wrapper.eq("fileId",fileId);
        List<SjIssueRecycling> sjIssueRecyclings = super.selectList(wrapper);
        for (SjIssueRecycling sjIssueRecycling : sjIssueRecyclings) {
            if (sjIssueRecycling.getAccepter()!=null&&!"".equals(sjIssueRecycling.getAccepter())){
                JyUser jyUser = jyUserMapper.selectById(sjIssueRecycling.getAccepter());
                sjIssueRecycling.setAccepterName(jyUser.getName());
            }
            if (sjIssueRecycling.getRecyclingPerson()!=null && !"".equals(sjIssueRecycling.getRecyclingPerson())){
                JyUser jyUser = jyUserMapper.selectById(sjIssueRecycling.getRecyclingPerson());
                sjIssueRecycling.setRecyclingPersonName(jyUser.getName());
            }
            if (sjIssueRecycling.getIssuer()!=null && !"".equals(sjIssueRecycling.getIssuer())){
                JyUser jyUser = jyUserMapper.selectById(sjIssueRecycling.getIssuer());
                sjIssueRecycling.setIssuerName(jyUser.getName());
            }
        }
        return sjIssueRecyclings;
    }
}
